import * as dto from './DTO';
import {request, handleFetchResultNotification, REQUEST_TYPE} from '../utils';
import stringify from 'Shared/utils/stringify';
import {formatMessage} from './intl';
const baseUrl = '/parts/api/v1';

const getInitdesc = formatMessage({
    id: 'api.message.getInitdesc',
    defaultMessage: '初始化备件箱单发票导出'
});
const getListDesc = formatMessage({
    id: 'api.message.getListDesc',
    defaultMessage: '查询备件箱单发票导出'
});
const getDealerDesc = formatMessage({
    id: 'api.message.getDealerDesc',
    defaultMessage: '查询总代编号'
});

const getDealerSimpleDesc = formatMessage({
    id: 'api.message.getDealerSimpleDesc',
    defaultMessage: '快捷查询总代编号'
});

const getlistExcelDesc = formatMessage({
    id: 'api.message.getlistExcelDesc',
    defaultMessage: '预箱单导出'
});
const getinvoiceExcelDesc = formatMessage({
    id: 'api.message.getinvoiceExcelDesc',
    defaultMessage: '预发票导出'
});
const getnoticeExcelDesc = formatMessage({
    id: 'api.message.getnoticeExcelDesc',
    defaultMessage: '确认通知书导出'
});
const getorderExcelDesc = formatMessage({
    id: 'api.message.getorderExcelDesc',
    defaultMessage: '货运委托书导出'
});
const getpackingExcelDesc = formatMessage({
    id: 'api.message.getpackingExcelDesc',
    defaultMessage: '箱单发票导出'
});
const getConfrimExcelDesc = formatMessage({
    id: 'api.message.getConfrimExcelDesc',
    defaultMessage: '出运确认书导出'
});
//初始化
export const getInitData = () => request(`${baseUrl}/ui/partInvoiceExport/init`, null, dto.InitData)
    .then(handleFetchResultNotification(REQUEST_TYPE.initQuery, getInitdesc));

// 查询订单列表
export const getList = pageOption => {
    const queryString = stringify(pageOption);
    return request(`${baseUrl}/partInvoiceExports?${queryString}`, null, dto.List)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getListDesc));
};
// 预箱单导出
export const getListExcelDesc = id => request(`${baseUrl}/partInvoiceExports/${id}/deliveryPackingListExcel`, null)
    .then(handleFetchResultNotification(REQUEST_TYPE.submit, getlistExcelDesc))
    .then(res => res.data);
// 预发票导出
export const getInvoiceExcelDesc = id => request(`${baseUrl}/partInvoiceExports/${id}/prePartInvoiceExcel`, null)
    .then(handleFetchResultNotification(REQUEST_TYPE.submit, getinvoiceExcelDesc))
    .then(res => res.data);
// 确认通知书导出
export const getNoticeExcelDesc = id => request(`${baseUrl}/partInvoiceExports/${id}/partShipNoticeExcel`, null)
    .then(handleFetchResultNotification(REQUEST_TYPE.submit, getnoticeExcelDesc))
    .then(res => res.data);
// 货运委托书导出
export const getOrderExcelDesc = id => request(`${baseUrl}/partInvoiceExports/${id}/partShipOrderExcel`, null)
    .then(handleFetchResultNotification(REQUEST_TYPE.submit, getorderExcelDesc))
    .then(res => res.data);
// 箱单发票导出
export const getPackingExcelDesc = id => request(`${baseUrl}/partInvoiceExports/${id}/commercialInvoiceAndPackingListExcel`, null)
    .then(handleFetchResultNotification(REQUEST_TYPE.submit, getpackingExcelDesc))
    .then(res => res.data);
//出运确认书导出
export const getConfirmExcelDesc = id => request(`${baseUrl}/partInvoiceExports/${id}/partShipConfirmExcel`, null)
    .then(handleFetchResultNotification(REQUEST_TYPE.submit, getConfrimExcelDesc))
    .then(res => res.data);
